﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Hartley.ApplicationLogic;
using Hartley.DTOs;
namespace WebApplication1
{
    public partial class AddAthleticData : System.Web.UI.Page
    {
        AdminAL adminAL = new AdminAL();
        StudentAL studentAL = new StudentAL();
        AthleticAL athleticAL = new AthleticAL();

        public Guid SelectedAthleticEvent
        {
            get
            {
                if (Session["AthleticEventId"] == null)
                {
                    return athleticAL.GetAthleticEvents()[0].AthleticEventId;
                }
                else
                {
                    return new Guid(Session["AthleticEventId"].ToString());
                }
            }
            set
            {
                Session["AthleticEventId"] = value;
            }
        }

        public Guid SelectedStudent
        {
            get
            {
                if (Session["StudentId"] == null)
                {
                    return studentAL.GetStudents()[0].StudentId;
                }
                else
                {
                    return new Guid(Session["StudentId"].ToString());
                }
            }
            set
            {
                Session["StudentId"] = value;
            }
        }

        protected override void OnPreRenderComplete(EventArgs e)
        {
            base.OnPreRenderComplete(e);

            List<AthleticEventDTO> athleticEventDTO = athleticAL.GetAthleticEvents();
            List<StudentDTO> studentDTO = studentAL.GetStudents();
            ddlAthleticEventName.DataSource = athleticEventDTO;
            ddlAthleticEventName.DataTextField = "EventName";
            ddlAthleticEventName.DataValueField = "AthleticEventId";
            ddlAthleticEventName.SelectedValue = SelectedAthleticEvent.ToString();
            ddlAthleticEventName.DataBind();


            ddlAthleticDataStudent.DataSource = studentDTO;
            ddlAthleticDataStudent.DataTextField = "FullName";
            ddlAthleticDataStudent.DataValueField = "StudentId";
            ddlAthleticDataStudent.SelectedValue = SelectedStudent.ToString();
            ddlAthleticDataStudent.DataBind();
            
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnStudentAdd_Click(object sender, EventArgs e)
        {
            AthleticDataDTO athleticDataDTO = new AthleticDataDTO
            {
                AthleticEventId = new Guid(ddlAthleticEventName.SelectedValue),
                StudentId = new Guid(ddlAthleticDataStudent.SelectedValue),
                Year = Convert.ToInt32(ddlAthleticDataYr.Text),
                Place = ddlAthleticDataPlace.SelectedValue,
                LevelName = ddlAthleticDataAtLevel.SelectedValue,
               // ModifiedBy = "Tharsan",
                ModifiedTime = DateTime.Now
            };
            AthleticAL athleticAL = new AthleticAL();
            athleticAL.saveAthleticData(athleticDataDTO);


        }

        protected void ddlAthleticEventName_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectedAthleticEvent = new Guid(ddlAthleticEventName.SelectedValue);

        }

        protected void ddlAthleticDataStudent_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectedStudent =new Guid(ddlAthleticDataStudent.SelectedValue);
        }
    }
}
